package com.bilibili.juc.tl;


import java.util.Random;
import java.util.concurrent.TimeUnit;

class MyHouse{
    int salecount = 0;
    public synchronized void saleHouse()
    {
        ++salecount;
    }
}
public class ThreadLocalDemo01 {

    public static void main(String[] args) {
        MyHouse house = new MyHouse();

        for(int i =1;i<=5;i++) {
            new Thread(
                    ()->{
                        int size = new Random().nextInt(5)+1 ;
                        System.out.println(size);
                        for(int j = 1;j<=size; j++){
                            house.saleHouse();
                        }
                    }
           ,String.valueOf(i)).start();
        }

        try { TimeUnit.MILLISECONDS.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); }

        System.out.println(Thread.currentThread().getName()+"\t"+"共计卖出多少套"+house.salecount);
    }
}
